﻿using System;

public class Node<T>
{
    public T Data { get; set; }
    public Node<T> Next { get; set; }

    public Node(T data)
    {
        Data = data;
        Next = null;
    }
}

public class GenericLinkedList<T>
{
    public Node<T> Head { get; private set; }

    public void AddLast(T value)
    {
        var newNode = new Node<T>(value);
        if (Head == null)
        {
            Head = newNode;
        }
        else
        {
            var current = Head;
            while (current.Next != null)
            {
                current = current.Next;
            }
            current.Next = newNode;
        }
    }

    public void ForEach(Action<T> action)
    {
        var current = Head;
        while (current != null)
        {
            action(current.Data);
            current = current.Next;
        }
    }
}